<?php

	$this->Html->script(array('flexigrid.pack'), false);
	$this->Html->css('flexigrid', null, array('inline' => false));
	
?>

<table id="flex" style="display: none"></table>

<script type="text/javascript">

    $("#flex").flexigrid({
        
        url: '<?php echo $this->Html->url(array('controller' => 'alunos', 'action' => 'grid')); ?>',
        
        dataType: 'json',
        colModel : [
            {display: 'Codigo',     name : 'id', 	        width :  40, sortable : true, align: 'center', hide: true},
            {display: 'Nome', 	    name : 'nome', 	        width : 300, sortable : true, align: 'left'},
            {display: 'Situção', 	name : 'situacao', 	    width : 100, sortable : true, align: 'left',hide: true}
        ],
        buttons : [
            {name: 'Lançar Eventos', bclass: 'add', onpress : actions},
            {name: 'Imprimir', bclass: 'imprimir', onpress : actions},
            {separator: true}
        ],
        searchitems : [
            {display: 'Nome',      name : 'Aluno.nome', isdefault: true}
            
        ],
        sortname: "nome",
        sortorder: "asc",
        usepager: true,
        useRp: true,
        rp: 1000,
        rpOptions: [10,15,20,25,40,1000],
        title: false,
        width: '100%',
        height: 270,
        singleSelect: true,
        errormsg:'Erro de conexão',
        pagestat:'Exibindo de {from} a {to} de um total de {total} registros.',
        pagetext:'Página',
        outof:'de',
        findtext:'Busca',
        procmsg:'Processando, por favor aguarde ...',
        nomsg:'Nenhum item'
    });

    $('#flex').dblclick( function(){
        var id = $('.trSelected').find('td[abbr="id"]').text();
        if(id != '')
            $(location).attr('href','<?php echo $this->Html->url(array('controller' => 'aluno_eventos', 'action' => 'grid_eventos')); ?>/' + id);
    });    
    
    function actions(com, grid) {
        var id = $('.trSelected', grid).find('td[abbr="id"]').text();
        switch(com) {
            case "Lançar Eventos":
            	if(id != ''){
                	$(location).attr('href','<?php echo $this->Html->url(array('controller' => 'aluno_eventos', 'action' => 'grid_eventos')); ?>/' + id);
            	}else
                    alert('Selecione um registro primeiro!');
                break;
            case "Imprimir":
               	$(location).attr('href','<?php echo $this->Html->url(array('controller' => 'aluno_eventos', 'action' => 'imprimir')); ?>');
                break;
		}
	}
</script>